// 获取用户token
export const getUserToken = () => {
  return localStorage.getItem('user_token')
}

// 设置用户token
export const setUserToken = (token) => {
  localStorage.setItem('user_token', token)
}

// 移除用户token
export const removeUserToken = () => {
  localStorage.removeItem('user_token')
}

// 检查用户token是否存在
export const hasUserToken = () => {
  return !!getUserToken()
}

// 检查token是否过期
export const isTokenExpired = (token) => {
  if (!token) return true
  
  try {
    const payload = JSON.parse(atob(token.split('.')[1]))
    return payload.exp * 1000 < Date.now()
  } catch (error) {
    return true
  }
}